package com.mall.user.controller;


import com.mall.common.response.CommonResponse;
import com.mall.constant.enums.CommonStatus;
import com.mall.constant.strings.SuccessMsg;
import com.mall.entity.TbUser;
import com.mall.user.annotation.UserLoginToken;
import com.mall.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 用户控制器
 *
 * @author SY
 * @date 2021/07/18
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 发送验证码
     */
    @GetMapping("/sendYzm")
    public CommonResponse sendYzm(String tel){
        return userService.sendYzm(tel);
    }

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public CommonResponse login(@RequestBody TbUser user){
        return userService.login(user);
    }

    /**
     *     用户注册
     */
    @GetMapping("/register")
    public CommonResponse register(String tel,String yzm){
        return userService.register(tel,yzm);
    }

    /**
     *     设置密码
     */
    @PostMapping("/setPassword")
    public CommonResponse setPassword(@RequestBody TbUser user){
        return userService.setPassword(user);
    }

    /**
     * 获取个人信息
     * @param tel
     * @return
     */
    @GetMapping("/getPersonalDetails")
    public CommonResponse<TbUser> getPersonalDetails(String tel){
        return userService.getPersonalDetails(tel);
    }

    @UserLoginToken
    @GetMapping("/getMessage")
    public CommonResponse getMessage(){
        return new CommonResponse(CommonStatus.VALID.getCode(), SuccessMsg.SUCCESS_CODE_200);
    }

}
